﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using grproLib;
using Zwms.Data.BusinessObjects;



namespace Zwms.Client.CommonUI
{
    public partial class PrintViewerForm : BaseForm
    {
        GridppReport Report = new GridppReport();
        private IGRField _barCodeField;
		private IGRField _goodsNameField;
        IList<BilInPlanBillDetail> _tempList = null;
        private string _sDate = "";
        public PrintViewerForm(IList<BilInPlanBillDetail> recordList,string sDate)
        {
            InitializeComponent();
            _tempList = recordList;
            _sDate = sDate;

            Report.Initialize += new _IGridppReportEvents_InitializeEventHandler(ReportInitialize);
            Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecord);
            try
            {
                //ServiceReferenceZwms.ServiceZwmsClient client
                //    = new ServiceReferenceZwms.ServiceZwmsClient();
                //SysConfig record =   client.GetSysConfig();
                //if (record == null)
                //{
                //    return;
                //}
                //else
                //{
                //    Report.DetailGrid.Recordset.ConnectionString = record.PrinterCfg;
                //}
                Report.LoadFromFile(Application.StartupPath + string.Format(@"\Reports\条码标签.grf"));


                //foreach (BilInPlanBillDetail record in _tempList)
                //{
                //    Report.DetailGrid.Recordset.Append();
                //    _barCodeField.AsString = string.Format("{0}#{1}", record.GoodsCode, _sDate);
                //    _goodsNameField.AsString = record.GoodsName;
                //    Report.DetailGrid.Recordset.Post();
                //}
              
                
                //设置报表查询显示器控件的关联报表对象
                axGRPrintViewer1.Report = Report;

                //启动报表运行
                axGRPrintViewer1.Start();
            }
            catch
            {

            }

        }
        private void ReportInitialize()
        {
            _barCodeField = Report.FieldByName("BarCode");
            _goodsNameField = Report.FieldByName("GoodsName");
        }

        private void ReportFetchRecord()
        {
            foreach (BilInPlanBillDetail record in _tempList)
            {
                Report.DetailGrid.Recordset.Append();
                _barCodeField.AsString = string.Format("{0}#{1}",record.GoodsCode,_sDate);
                _goodsNameField.AsString = record.GoodsName;
                Report.DetailGrid.Recordset.Post();
            }
        }
    }
}
